import datetime

from app.core.extensions import db


class CardRecord(db.Model):
    __tablename__ = 'card_record'

    id = db.Column(db.BigInteger, primary_key=True)
    user_id = db.Column(db.BigInteger, nullable=False)
    admin_id = db.Column(db.BigInteger)
    count = db.Column(db.Integer, nullable=False)
    remark = db.Column(db.String(255))
    created_at = db.Column(db.DateTime, default=datetime.datetime.now)
    tenant_id = db.Column(db.Integer, nullable=True, comment='租户ID')

    def to_dict(self):
        return {
            'id': self.id,
            'user_id': self.user_id,
            'admin_id': self.admin_id,
            'count': self.count,
            'remark': self.remark,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'),
            'tenant_id': self.tenant_id
        }
